import pygame, sys, random
from pygame.locals import *

# 定义游戏参数
FPS = 30
WINDOW_WIDTH = 600
WINDOW_HEIGHT = 600
BOARD_SIZE = 5  # 棋盘大小为 5 * 5

# 定义颜色常量
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)

# 初始化 Pygame
pygame.init()
fps_clock = pygame.time.Clock()

# 设置窗口
window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption('跳棋游戏')

# 加载棋盘
board = pygame.Surface((WINDOW_WIDTH, WINDOW_HEIGHT))
board.fill(WHITE)
radius = 20  # 棋子半径
space = 5  # 棋盘线条与棋子间隔
margin = (WINDOW_WIDTH - (BOARD_SIZE - 1) * (2*radius+space)) // 2
for row in range(BOARD_SIZE):
    for col in range(BOARD_SIZE):
        x = margin + (2*radius+space) * col
        y = margin + (2*radius+space) * row
        pygame.draw.circle(board, BLACK, (x, y), radius)
window.blit(board, (0, 0))

# 初始化棋子
pieces = []
for i in range(BOARD_SIZE * BOARD_SIZE):
    piece = pygame.Surface((radius*2, radius*2))
    piece.set_colorkey((0, 0, 0))
    pygame.draw.circle(piece, BLACK, (radius, radius), radius)
    pieces.append(piece)

# 让玩家选择第一个被拿走的棋子
selected_piece = None
while selected_piece is None:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        elif event.type == MOUSEBUTTONUP:
            x, y = event.pos
            for i in range(len(pieces)):
                piece_x = margin + (2*radius+space) * (i % BOARD_SIZE)
                piece_y = margin + (2*radius+space) * (i // BOARD_SIZE)
                if x > piece_x and x < piece_x + radius*2 and \
                   y > piece_y and y < piece_y + radius*2:
                    selected_piece = i
                    pieces[selected_piece] = None
                    break

pygame.display.update()
